package org.hashdb.client.net.bio.msg;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hashdb.client.net.bio.MessageType;

import java.io.Serial;
import java.io.Serializable;
import java.util.UUID;

/**
 * Date: 2023/11/20 20:55
 *
 * @author huanyuMake-pecdle
 * @version 0.0.1
 */
@ToString
@EqualsAndHashCode
public abstract class Message implements IMessage, Serializable, Cloneable {
    @Serial
    private static final long serialVersionUID = 31895374964L;

    @Getter
    @Setter
    protected UUID id;

    @Getter
    @Setter
    protected long timestamp;

    @Getter
    @Setter
    protected String data;
    @JsonIgnore
    protected boolean shouldConsume = true;

    @Override
    public Message clone() {
        try {
            return (Message) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }


    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    public void setType(MessageType type) {
    }

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    abstract public MessageType getType();

    public boolean isShouldConsume() {
        return shouldConsume;
    }

    public void setShouldConsume(boolean shouldConsume) {
        this.shouldConsume = shouldConsume;
    }
}
